package dmmm.main;

import java.io.*;

import javax.swing.*;
import javax.swing.event.*;

import dmmm.gui.GuiScheme;
import dmmm.shemes.*;

@SuppressWarnings("serial")
public class Menu extends JList<String> {
	private Main myMain;

	public Menu(Main m, PrintStream log) {
		myMain = m;
		if (log == null) {
			log = System.out;
		}

		log.println();
		log.println("MenuLoader: ");
		log.println();

		final DefaultListModel<String> listModel = new DefaultListModel<String>();
		listModel.addElement("Sistem");
		listModel.addElement(" Procesor");
		listModel.addElement("     Operaciona jedinica");
		listModel.addElement("          Bus");
		listModel.addElement("          Fetch 1");
		listModel.addElement("          Fetch 2");
		listModel.addElement("          Fetch 3");
		listModel.addElement("          Addr");
		listModel.addElement("          Exec 1");
		listModel.addElement("          Exec 2");
		listModel.addElement("          Exec 3");
		listModel.addElement("          Exec 4");
		listModel.addElement("          Intr 1");
		listModel.addElement("          Intr 2");
		listModel.addElement("          Intr 3");
		listModel.addElement("     Upravljacka jedinica");
		listModel.addElement("          Uprav. signali operacione jed.");
		listModel.addElement("          Uprav. signali upravljacke jed.");
		listModel.addElement(" Memorija");
		listModel.addElement("      Operaciona jedinica");
		listModel.addElement("      Upravljacka jedinica");

		setModel(listModel);

		setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		setLayoutOrientation(JList.VERTICAL);

		addListSelectionListener(new ListSelectionListener() {

			@Override
			public void valueChanged(ListSelectionEvent e) {
				GuiScheme currentScheme = null;
				String selected = listModel.getElementAt(Menu.this
						.getSelectedIndex());

				if (selected.equals("Sistem")) {
					currentScheme = Sistem.getGui();
				} else if (selected.equals(" Procesor")) {
					currentScheme = Cpu.getGui();
				} else if (selected.equals("          Addr")) {
					currentScheme = Adr1.getGui();
				} else if (selected.equals("          Bus")
						|| selected.equals("     Operaciona jedinica")) {
					currentScheme = Bus1.getGui();
				} else if (selected.equals("     Upravljacka jedinica")) {
					currentScheme = Counter.getGui();
				} else if (selected.equals("          Exec 1")) {
					currentScheme = Exec1.getGui();
				} else if (selected.equals("          Exec 2")) {
					currentScheme = Exec2.getGui();
				} else if (selected.equals("          Exec 3")) {
					currentScheme = Exec3.getGui();
				} else if (selected.equals("          Exec 4")) {
					currentScheme = Exec4.getGui();
				} else if (selected.equals("          Fetch 1")) {
					currentScheme = Fetch1.getGui();
				} else if (selected.equals("          Fetch 2")) {
					currentScheme = Fetch2.getGui();
				} else if (selected.equals("          Fetch 3")) {
					currentScheme = Fetch3.getGui();
				} else if (selected.equals("          Intr 1")) {
					currentScheme = Intr1.getGui();
				} else if (selected.equals("          Intr 2")) {
					currentScheme = Intr2.getGui();
				} else if (selected.equals("          Intr 3")) {
					currentScheme = Intr3.getGui();
				} else if (selected.equals(" Memorija")) {
					currentScheme = Mem.getGui();
				} else if (selected.equals("      Operaciona jedinica")) {
					currentScheme = Mem1.getGui();
				} else if (selected.equals("      Upravljacka jedinica")) {
					currentScheme = Mem2.getGui();
				} else if (selected
						.equals("          Uprav. signali operacione jed.")) {
					currentScheme = Oper1.getGui();
				} else if (selected
						.equals("          Uprav. signali upravljacke jed.")) {
					currentScheme = Uprav1.getGui();
				}
				if (currentScheme != null) {
					myMain.setCurrentScheme(currentScheme);
				}
			}
		});
	}
}
